import Component from './Component.js';
// import PIXI from './PIXI.js';
let app = window.app;
export default class Timer extends Component {
  
  constructor(width, height){
    super();

    this.timer = 0;

    this.width = width;
    this.height = height;
    this.vs = width/375;

    const sprite =  new PIXI.Container();
    sprite.width = width;
    sprite.height = height;
    sprite.x = 0;
    sprite.y = 0;
    this.sprite = sprite;
    window.app.stage.addChild(this.sprite);
    this.createScore();
    this.scoreText2(30);
  }
  createScore(){
    const sprite = new PIXI.Sprite(window.resources["timer"].texture);
		sprite.width = 130 * this.vs;
		sprite.height = 48 * this.vs;
		sprite.x = 17 * this.vs;
    sprite.y = 35 * this.vs;
    this.scoreSprite = sprite;
    this.sprite.addChild(sprite);
  }
  scoreText2(score){
    this.scoreSprite.removeChildren();
    const y = [0, 56, 112, 168, 224, 280, 336, 392, 448, 504];
    let scoreString = String(score);
    let left =  426 - scoreString.length*25/1.5;
    scoreString.split('').forEach((number, idx)=>{
      const texture = new PIXI.Texture(window.resources["number2"].texture);  
      let width = 25;
      let height = 36;  //console.log(y)
      texture.frame = new PIXI.Rectangle(0, y[number], width, height);
      const sprite = new PIXI.Sprite(texture);
      sprite.width = width   * 1.3;
      sprite.height = height * 1.3;
      sprite.x = left + sprite.width * idx ;
      sprite.y = (97 - sprite.height/2);
      this.scoreSprite.addChild(sprite);
    })
  }

  update(time){ 
    this.scoreText2(time);
  }
}


